#!/bin/bash
eth=$1
if [ -s $eth ];then
  eth="lo"
fi
in_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
out_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')
sleep 1
in=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
out=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')
dif_in=$(((in-in_old)))
dif_in=$((dif_in/1024))
dif_out=$(((out-out_old)))
dif_out=$((dif_out/1024))
echo "{\"in\":${dif_in},\"out\":${dif_out}}"
